/********************************************************/
/*                                                      */
/*         CLASS ColorPickerPlugginPantone              */
/*------------------------------------------------------*/
/*------------------------------------------------------*/
/*  Dépendances:                                        */
/*      -colorPickerPluggin.pantone.local.<lang>.js     */
/*      -colorPickerPluggin.pantone.global.js           */
/*      -colorPickerPluggin.pantone.dataCollection.js   */
/*                                                      */
/********************************************************/


function ColorPickerPlugginPantone()
{
	this.name=CP_PLUGGIN_PANTONE_name;
	this.codeName='pantone';
	this.id=uniqueIDInDOM();
	this.versionColorPickerNeeded='1.0';
	this.uniqueRegistration=true;
	
	//definition du type de pluggin
	this.needWarning=true;		   //indique si ce pluggin nécessite une zone de warning
	this.assignedWarningId=0;      //numéro de warning 0 à 3 possible
	this.needSelectorEntry=true;  //indique si ce pluggin définit un selecteur
	this.interceptRefreshColor=true;//indique si ce pluggin doit traiter this.interceptRefreshColor

	
	this.colorPicker=null; 	//Référence au color picker utilisant ce pluggin
	
	this.active=false;
	
	//spécifique a ce pluggin
	this.refreshColorThread=null;
	
	//interface
	this.injectHTML=CP_PLUGGIN_PANTONE_injectHTML;
	this.init=CP_PLUGGIN_PANTONE_init;
	this.refreshCurrentColor=CP_PLUGGIN_PANTONE_refreshCurrentColor;
	this.showSelector=CP_PLUGGIN_PANTONE_showSelector;
	this.hideSelector=CP_PLUGGIN_PANTONE_hideSlector;
}


/*************************************************/
/*                                               */
/*       Méthode privées du pluggin pantone      */
/*                                               */
/* Par commodité j'ai indéxer toutes les méthodes*/
/*  par CP_PLUGGIN_PANTONE_                      */
/*************************************************/

function CP_PLUGGIN_PANTONE_init()
{
}

function CP_PLUGGIN_PANTONE_refreshCurrentColor()
{
	if(this.refreshColorThread!=null) { clearTimeout(this.refreshColorThread); }
	
	this.refreshColorThread=window.setTimeout("CP_PLUGGIN_PANTONE_isPantoneMatch('"+this.colorPicker.id+"',"+this.assignedWarningId+");",CP_PLUGGIN_PANTONE_REFRESH_THREAD_DECAY);
}

function CP_PLUGGIN_PANTONE_isPantoneMatch(colorPickerId,assignedWarningId)
{
	var colorPicker=CP_findColorPickerById(colorPickerId);
	var current=colorPicker.get('hex');
	var test=CP_PLUGGIN_PANTONE_isPantoneColor(current);
	
	var cell=document.getElementById(colorPicker.id+'_Warning'+assignedWarningId+'Td');
	
	if(test[0])  //c'est bien une couleur web protege
	{
		cell.innerHTML='&nbsp;';
		cell.style.backgroundColor='';
	}
	else
	{
		cell.style.backgroundColor=test[1];
		cell.innerHTML='<img id="'+colorPicker.id+'_pantoneSelector_'+assignedWarningId+'_'+test[1]+'" src="images/warning_pantone_15_18.gif" title="'+CP_PLUGGIN_PANTONE_reload_message+' : '+test[2]+' ('+CP_PLUGGIN_PANTONE_reload_double_clic+')" border="0" style="cursor:pointer;" onDblClick="CP_PLUGGIN_PANTONE_CLICK(event);">';
	}
	cell.style.innerHTML='red';
}

function CP_PLUGGIN_PANTONE_showSelector()
{
	this.active=true;
	document.getElementById(this.colorPicker.id+'_pluggin_selector_'+this.id).style.display='block';
}

function CP_PLUGGIN_PANTONE_hideSlector()
{
	this.active=false;
	document.getElementById(this.colorPicker.id+'_pluggin_selector_'+this.id).style.display='none';
}

//injection de code html supplémentaire nécessaire à ce pluggins
function CP_PLUGGIN_PANTONE_injectHTML()
{
	//on ajoute un div contenant le palette
	var html=CP_PLUGGIN_PANTONE_generatePantonePalette(this.colorPicker.id);
	document.body.innerHTML+='<div id="'+this.colorPicker.id+'_pluggin_selector_'+this.id+'" style="position:absolute; left:'+this.colorPicker.xDecal+'; top:'+this.colorPicker.yDecal+'; width:286px; height:256px; z-index:40; background-color:'+CP_PLUGGIN_PANTONE_BG_SELECTOR_PALETTE+'; display:none; overflow:auto;">'+html+'</div>';
	//on ajoute une entree au selecteur de palette
	var selector=document.getElementById(this.colorPicker.id+'_paletteSelector');
	selector.options[selector.options.length]=new Option(this.name,this.codeName,false,false);
}